<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;
use App\Http\Requests\ListPostRequest;

class ListController extends Controller
{
    //电影列表
   public function getFilm(Request $request)
    {

    	//每页显示几条
       	// $num = $request->input('num',20);
        
    	$videos = DB::table('video')
            ->where('tid','=','1')
            ->where('film','like','%'.$request->input('keyword').'%')
            ->paginate(15);

            
    	$content = DB::table('type')
    		->where('id','=','1')
    		->first();
    	//解析模板

    	//获取所有的请求参数
        $all = $request->all();
        $ad = DB::table('ad')->first();
    	return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
    }

    //电视剧列表
   public function getTv(Request $request)
    {

    	
			$videos = DB::table('video')
		        ->where('tid','=','2')
                ->where('film','like','%'.$request->input('keyword').'%')
                ->paginate(15);

    	$content = DB::table('type')
    		->where('id','=','2')
    		->first();
    	
    	//获取所有的请求参数
        $all = $request->all();
        $ad = DB::table('ad')->first();
    	return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
    }

    //动漫列表
   public function getComic(Request $request)
    {
    	$videos = DB::table('video')
            ->where('tid','=','3')
            ->where('film','like','%'.$request->input('keyword').'%')
            ->paginate(15);

    	$content = DB::table('type')
    		->where('id','=','3')
    		->first();
    	
    	//获取所有的请求参数
        $all = $request->all();
        $ad = DB::table('ad')->first();
    	return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
    }

    //原创列表
   public function getOriginal(Request $request)
    {
    	$videos = DB::table('video')
            ->where('tid','=','4')
            ->where('film','like','%'.$request->input('keyword').'%')
            ->paginate(15);

    	$content = DB::table('type')
    		->where('id','=','4')
    		->first();
    	
    	//获取所有的请求参数
        $all = $request->all();
        $ad = DB::table('ad')->first();
    	return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
    }

     //军事列表
    public function getMilitary(Request $request)
     {
        $videos = DB::table('video')
             ->where('tid','=','5')
             ->where('film','like','%'.$request->input('keyword').'%')
             ->paginate(15);

        $content = DB::table('type')
            ->where('id','=','5')
            ->first();
        
        //获取所有的请求参数
         $all = $request->all();
         $ad = DB::table('ad')->first();
        return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
     }

      //旅游列表
     public function getTourism(Request $request)
      {
         $videos = DB::table('video')
              ->where('tid','=','6')
              ->where('film','like','%'.$request->input('keyword').'%')
              ->paginate(15);

         $content = DB::table('type')
             ->where('id','=','6')
             ->first();
         
         //获取所有的请求参数
          $all = $request->all();
          $ad = DB::table('ad')->first();
         return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
      }


       //体育列表
      public function getSports(Request $request)
       {
          $videos = DB::table('video')
               ->where('tid','=','7')
               ->where('film','like','%'.$request->input('keyword').'%')
               ->paginate(15);

          $content = DB::table('type')
              ->where('id','=','7')
              ->first();
          
          //获取所有的请求参数
           $all = $request->all();
           $ad = DB::table('ad')->first();
          return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
       }


        //教育列表
      public function getEducation(Request $request)
       {
          $videos = DB::table('video')
               ->where('tid','=','8')
               ->where('film','like','%'.$request->input('keyword').'%')
               ->paginate(15);

          $content = DB::table('type')
              ->where('id','=','8')
              ->first();
          
          //获取所有的请求参数
           $all = $request->all();
           $ad = DB::table('ad')->first();
          return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
       }

       //教育列表
      public function getGame(Request $request)
       {
          $videos = DB::table('video')
               ->where('tid','=','9')
               ->where('film','like','%'.$request->input('keyword').'%')
               ->paginate(15);

          $content = DB::table('type')
              ->where('id','=','9')
              ->first();
          
          //获取所有的请求参数
           $all = $request->all();
           $ad = DB::table('ad')->first();
          return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
       }

        //自然列表
       public function getNatural(Request $request)
        {
           $videos = DB::table('video')
                ->where('tid','=','10')
                ->where('film','like','%'.$request->input('keyword').'%')
                ->paginate(15);

           $content = DB::table('type')
               ->where('id','=','10')
               ->first();
           
           //获取所有的请求参数
            $all = $request->all();
            $ad = DB::table('ad')->first();
           return view('home/list',['videos'=>$videos,'content'=>$content,'all'=>$all,'ad'=>$ad]);
        }

    public function getSearch(Request $request)
    {
    	$videos = DB::table('video')
    				->where('film','like','%'.$request->input('keyword').'%')
		        	->paginate(10);

                    //搜索总条数
                    $num = DB::table('video')
                    ->where('film','like','%'.$request->input('keyword').'%')
                    ->count();

	//获取所有的请求参数
                    
	$all = $request->all();

	return view('home/search',['videos'=>$videos,'all'=>$all,'num'=>$num]);

    }

    
	public function getResearch(Request $request)
	{
			switch($request->input('a'))
			{
				case 'max':
					$videos = DB::table('video')
					->where('film','like','%'.$request->input('keyword').'%')
					->orderBy('ctime', 'desc')
					->orderBy('click', 'desc')
	    	    	->paginate(10);
				break;
					
				case 'new':
					$videos = DB::table('video')
					->where('film','like','%'.$request->input('keyword').'%')
					->orderBy('ctime', 'desc')
					->paginate(10);

				break;
	
					case 'more':
						$videos = DB::table('video')
						->where('film','like','%'.$request->input('keyword').'%')
						->orderBy('click', 'desc')
						->paginate(10);
				break;

			}
           
           //搜索总条数
           $num = DB::table('video')
           ->where('film','like','%'.$request->input('keyword').'%')
           ->count();
           
             $all = $request->all();
		return view('home/search',['videos'=>$videos,'all'=>$all,'num'=>$num]);
		
	}

  // //智能搜索提示获取数据
  public function getZnsearch(Request $request)
  {       
          $search = DB::table('video')
              ->select(DB::raw('film'))
              ->get();

              foreach ($search as $k => $v) {
                $res[]=$v->film;
              }
         echo json_encode($res);
  }

}
